package com.afkt.project.ui.slice;

import com.ohos.afkt.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.webengine.*;
import ohos.media.image.PixelMap;
import ohos.net.http.SslError;

public class WebViewSlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_web_view);

        WebView webView = (WebView) findComponentById(ResourceTable.Id_webview);
        final String url = "https://www.csdn.net/";

        webView.setWebAgent(new WebAgent(){
            @Override
            public boolean isNeedLoadUrl(WebView webView, ResourceRequest request) {
                return super.isNeedLoadUrl(webView, request);
            }

            @Override
            public void onLoadingPage(WebView webView, String url, PixelMap icon) {
                super.onLoadingPage(webView, url, icon);
            }

            @Override
            public void onPageLoaded(WebView webView, String url) {
                super.onPageLoaded(webView, url);
            }

            @Override
            public void onLoadingContent(WebView webView, String url) {
                super.onLoadingContent(webView, url);
            }

            @Override
            public void onError(WebView webView, ResourceRequest request, ResourceError error) {
                super.onError(webView, request, error);
            }

            @Override
            public void onSslError(WebView webView, SslError error) {
                super.onSslError(webView, error);
            }

            @Override
            public ResourceResponse processResourceRequest(WebView webView, ResourceRequest request) {
                return super.processResourceRequest(webView, request);
            }
        });
        webView.load(url);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
